package com.irm.controller;

import com.gadgets.framework.annotation.RoleAuthCheck;
import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.FeginRequestMapUtil;
import com.irm.dto.DraftOperDTO;
import com.irm.dto.MockInfoQueryDTO;
import com.irm.dto.MsgLogQueryDTO;
import com.irm.fegin.IrmDraftController;
import com.irm.pojo.IrmMockInfo;
import com.irm.pojo.IrmMsgLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2022-01-20
 */
@RestController
@RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "bm04")
public class GadgetsBm04Fork {

    @Autowired
    private IrmDraftController irmDraftController;

    /**
     * 报文操作方法
     * @param request                       网络请求
     * @param response                      网络应答
     * @param draftOperDTO                  报文申请信息
     * @return                              操作结果
     * @throws GadgetsServiceException      异常信息
     */
    @SuppressWarnings("rawtypes")
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/oper.do")
    public HttpBaseResp operationDraftOper(HttpServletRequest request, HttpServletResponse response, DraftOperDTO draftOperDTO) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(draftOperDTO, requestParam);
        return irmDraftController.operationDraftOper(requestParam);
    }

    /**
     * 查询 MockInfo 表信息
     * @param request                       网络请求
     * @param response                      网络应答
     * @param mockInfoQueryDTO              报文申请信息
     * @param pagination                    分页信息
     * @return                              应答结果
     * @throws GadgetsServiceException      异常信息
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/queryMockInfo.do")
    public HttpBaseResp<IrmMockInfo> queryMockInfo(HttpServletRequest request, HttpServletResponse response, MockInfoQueryDTO mockInfoQueryDTO, Pagination pagination) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(mockInfoQueryDTO, requestParam);
        FeginRequestMapUtil.parseRequestParam(pagination, requestParam);
        return irmDraftController.queryMockInfo(requestParam);
    }

    /**
     * 报文信息查询
     * @param request                       网络请求
     * @param response                      网络应答
     * @param queryDTO                      查询条件
     * @param pagination                    分页信息
     * @return                              应答结果
     * @throws GadgetsServiceException      服务异常
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/queryMsgLog.do")
    public HttpBaseResp<IrmMsgLog> queryMsgLog(HttpServletRequest request, HttpServletResponse response, MsgLogQueryDTO queryDTO, Pagination pagination) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        FeginRequestMapUtil.parseRequestParam(queryDTO, requestParam);
        FeginRequestMapUtil.parseRequestParam(pagination, requestParam);
        return irmDraftController.queryMsgLog(requestParam);
    }

    /**
     * 报文信息查询
     * @param msgLogId                      irm_msg_log的主键ID
     * @return                              应答结果
     * @throws GadgetsServiceException      服务异常
     */
    @RoleAuthCheck
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/queryMsgContent.do")
    public HttpBaseResp<String> getMsgContant(Long msgLogId) throws GadgetsServiceException{
        HashMap<String, Object> requestParam = new HashMap<>();
        requestParam.put("msgLogId", msgLogId);
        return irmDraftController.getMsgContant(requestParam);
    }

}
